%get frequency of top 4 color
function [fre] = FreTop4(data)
    data = imread(data);
    %[quan, map] = rgb2ind(data,256);
    gray = rgb2gray(data);
    f = imhist(gray(:),256);
    f = sort(f,'descend');
    fre = (f(1,1) + f(2,1) + f(3,1) + f(4,1) + f(5,1) + f(7,1) + f(8,1) + f(9,1) + f(10,1))/sum(f);    
end
    
function [dist] = AvgDist(map)
    dist = 0;
    n = size(map,1);
    for i=1:n-1
        for j=i+1:n
            dist = dist+Distance(map(i,:),map(j,:));            
        end
    end
    dist = dist/(n*(n-1)/2);
end
    
function [dist] = Distance(a,b)
    temp = a-b;
    temp = temp.^2;
    dist = sqrt(sum(temp(:)));
end